#include "CommonStructs.h"
#include "WinSockUtils.h"
#include "Consts.h"
#include "BinaryStream.h"


#define		SERVER_ADDRESS	"127.0.0.1"

//------------------------- RL SYSTEM OPERATIONS
//--- START

/*
  Attempts to register to the server.
  Return type is defined in the "Consts.h" file.
*/
int
	RL_ATTEMP_REGISTER( 
	char* user, 
	char* password 
	)
{
	const char* data[2] = {user, password};
	int returned = 0;
	int result = WinSock_Send(SERVER_ADDRESS, 4468, (char*)data, &returned);
	if(result != SOCK_ERROR_WINSOCK | SOCK_ERROR_WSA)
	{
		return returned;
	} 
	else 
	{
		return -1;
	}
}


/*
  Attempts to login to the server using the given credentials.
  PARAMETER "IP" is the remote IP of the current user (yours).
  PARAMETER "data_returned" is the current gamer_t structure of the user into the server.
*/
void
	RL_ATTEMP_LOGIN(char* user, char* password, char* ip, gamer_t* data_returned)
{
	const char* data[3] = {user, password, ip};
	BYTE* data2;
	int result = WinSock_Send(SERVER_ADDRESS, 4468, (char*)data, &data2);
	if(result != SOCK_ERROR_WINSOCK | SOCK_ERROR_WSA)
	{
		BinaryReader reader(data2);
		int ID = reader.ReadInt32();
		gamer_t gamer;
		memset(&gamer, 0x00, sizeof(gamer));
		gamer.CurrentGame = 0;
		gamer.ID = ID;
		gamer.IsInGame = false;
		gamer.IsOnline = true;
		gamer.Password = password;
		gamer.Username = user;
		*data_returned = gamer;
	}
	else
	{
		return;
	}
}
//--- END


//-------------------------  